package cn.com.nes.site.entity.em.workOrder;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 可撤销安装工单状态枚举 - 合并了工单状态和接单状态
 * param_type = 337
 */
@Getter
public enum CancelWorkOrdersStatusEnum {

    ORDER_STATUS_PREFIX("order_status_", "工单状态前缀",true),
    SERVICE_STATUS_PREFIX("service_status_", "接单状态前缀", true),
    ORDER_STATUS_0("order_status_0", "待派单", true),
    ORDER_STATUS_1("order_status_1", "待支援", true),
    ORDER_STATUS_2("order_status_2", "处理中", false), // 这个不启用是因为在本状态下,由接单状态表示
    ORDER_STATUS_3("order_status_3", "已完成", false),
    ORDER_STATUS_4("order_status_4", "已关闭", false),
    ORDER_STATUS_5("order_status_5", "已拒单", true),
    ORDER_STATUS_6("order_status_6", "待回访", false),
    ORDER_STATUS_7("order_status_7", "待审核", false),
    ORDER_STATUS_8("order_status_8", "已分单", false),
    SERVICE_STATUS_0("service_status_0", "未签到", true),
    SERVICE_STATUS_1("service_status_1", "已签到", true),
    SERVICE_STATUS_2("service_status_2", "处理完毕", false),
    SERVICE_STATUS_3("service_status_3", "待接单", true),
    SERVICE_STATUS_4("service_status_4", "等待配件", false),
    ;

    private final String key;

    private final String value;

    private final boolean enable; // 是否启用

    CancelWorkOrdersStatusEnum(String key, String value, boolean enable) {
        this.key = key;
        this.value = value;
        this.enable = enable;
    }

    public static String getStatusName(String status) {
        if (StrUtil.isBlank(status)) return StrUtil.EMPTY;

        List<String> statusNameList = new ArrayList<>();
        for (CancelWorkOrdersStatusEnum value : values()) {
            if (Arrays.asList(status.split(",")).contains(value.getKey())) {
                statusNameList.add(value.getValue());
            }
        }
        return String.join(",", statusNameList);
    }
}
